package com.ygo.feihua;

import android.app.*;
import android.content.*;
import android.net.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import cn.bmob.v3.datatype.*;
import cn.bmob.v3.listener.*;
import com.ygo.feihua.BmobTable.*;
import java.io.*;
import java.util.*;
import android.util.Log;
import android.graphics.Rect;
import android.support.v7.widget.*;

public class gvitem extends BaseAdapter
{
	private List<Zhuti> data;
	private Context context;
	private Zujian zujian;  
	private Gongju gj;


	public gvitem(Context context, List<Zhuti> data)
	{
		this.context = context;
		this.data = data;
        gj = Gongju.getdx(context);
	}
	
    public void sx(List<Zhuti> data)
	{
        this.data = data;
        notifyDataSetChanged();
    }
	
	public void addItem(Zhuti map)
	{
		data.add(map);
		notifyDataSetChanged();
	}
	
    public final class Zujian
	{  
		ImageView zt_item_tp;
        TextView zt_item_name;
		CardView zt_item_cv;
    }  
	@Override
	public int getCount()
	{
		return data.size();
	}

	@Override
	public Object getItem(int position)
	{
		return data.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent)
	{
		if (convertView == null)
		{  
            zujian = new Zujian();  
            //获得组件，实例化组件  

			convertView = LayoutInflater.from(context).inflate(
				R.layout.item_zhuti, null);	
		
			zujian.zt_item_tp = (ImageView) convertView.findViewById(R.id.zt_item_tp);
			zujian.zt_item_name = (TextView) convertView.findViewById(R.id.zt_item_name);
			zujian.zt_item_cv=(CardView) convertView.findViewById(R.id.zt_item_cv);
			convertView.setTag(zujian);  
		}
		else
		{ 
			zujian = (Zujian)convertView.getTag(); 		
		}
		
		gj.tuxian(data.get(position).getzttb(),zujian.zt_item_tp);
		zujian.zt_item_name.setText(data.get(position).getztname());
		
		zujian.zt_item_cv.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					Intent intent=new Intent(context, ZhutiXiangxi.class);
					intent.putExtra("id", data.get(position).getObjectId());
					context.startActivity(intent);
					// TODO: Implement this method
				}
			});
		return convertView;
	}
    
 
}
